package imsdk

import (
	"encoding/json"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/http"
)

type DeleteGroupMember struct {
	GroupID            string   `json:"GroupId"`             // 群ID
	Silence            int      `json:"Silence"`             // 是否静默删人。0表示非静默删人，1表示静默删人。静默即删除成员时不通知群里所有成员，只通知被删除群成员。不填写该字段时默认为0
	MemberToDelAccount []string `json:"MemberToDel_Account"` // 待删除的群成员
}

// DeleteGroupMember 删除群成员
func (s sdk) DeleteGroupMember(req DeleteGroupMember) bool {
	reqUrl := s.BuildRestfulUrl("/group_open_http_svc/delete_group_member")
	bytes, err := json.Marshal(req)
	if err != nil {
		global.Log.Error("delete member error: ", err)
		return false
	}
	result, err := http.HttpPost(reqUrl, string(bytes), connTimeoutMs, serveTimeoutMs, "application/json")
	resp := SendImResponse{}
	err = json.Unmarshal(result, &resp)
	if err != nil {
		global.Log.Error("delete member Unmarshal error: ", err)
		return false
	}
	if resp.ActionStatus == FailActionStatus {
		global.Log.Error("delete member error: ", err, "error message : ", resp.ErrorInfo, "error code:", resp.ErrorCode)
		return false
	}
	return true
}
